/*
 * 创建人 判断移动端当前环境
 */

const userAgent = window.navigator.userAgent.toLowerCase();
const isWeiChat = userAgent.indexOf('micromessenger') !== -1;
const isComWX = userAgent.indexOf('wxwork') !== -1;
const isInApp = (app) => (new Function(`retutn /(^|;\s)${app}\//`)((app + '').toLowerCase())).test(userAgent)
const isMiniProgram = isWeiChat && window.__wxjs_environment === 'miniprogram';
const isWeiChatH5 = isWeiChat && !(window.__wxjs_environment === 'miniprogram');
const isAndroid = userAgent.indexOf('android') > -1 || userAgent.indexOf("adr") > -1;
const isIOS = !!userAgent.match(/(iphone|ipod|ipad);?/);
const isBrowser = !isWeiChat && (isAndroid || isIOS);

export default {
    isInApp,
    isWeiChat,
    isMiniProgram,
    isWeiChatH5,
    isBrowser,
    isAndroid,
    isIOS,
    isComWX,
    get() {
        if (isMiniProgram && isComWX) {
            return 'work-wxmp'
        };
        if (isWeiChatH5 && isComWX) {
            return 'work-wxh5'
        };
        if (isMiniProgram) {
            return 'wxmp'
        };
        if (isWeiChatH5) {
            return 'wxh5'
        };
        if (isAndroid) {
            return 'android'
        };
        if (isIOS) {
            return 'ios'
        };
        return 'app'
    }
}